package com.starssea.mybatis.mapper;

import com.starssea.mybatis.po.ArticlePO;
import com.starssea.mybatis.provider.SqlProvider;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;

public interface ArticleRepository {
    // 定义Results
    @Select("")
    @Results(id = "NewBaseArticleMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "title", property = "title"),
            @Result(column = "summary", property = "summary"),
            @Result(column = "read_count", property = "readCount"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    ArticlePO articleMapper();

    // 使用提供者
    @ResultMap("NewBaseArticleMap")
    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    ArticlePO selectById(Integer id);

    @UpdateProvider(type = SqlProvider.class, method = "updateTime")
    int updateTime(Integer id, LocalDateTime updateTime);

    @InsertProvider(type = SqlProvider.class, method = "insert")
    int insert(ArticlePO articlePO);
}
